package dongbai.soft.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import dongbai.soft.dao.DelivererDao;
import dongbai.soft.entity.DelivererEntity;
import dongbai.soft.service.DelivererService;
import dongbai.soft.utils.Constant;
import dongbai.soft.utils.PageUtils;
import dongbai.soft.utils.Query;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("delivererService")
@SuppressWarnings("unchecked")
public class DelivererServiceImpl extends ServiceImpl<DelivererDao, DelivererEntity> implements DelivererService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Map<String, String> filter = (Map<String, String>) params.get("filter");

        IPage<DelivererEntity> page = this.page(
                new Query<DelivererEntity>().getPage(params),
                new QueryWrapper<DelivererEntity>().between("start_date", filter.get("startdate"), filter.get("enddate"))
                        .like("TRID", filter.get("TRID")).like("name", filter.get("name")).eq("status", Constant.STATE_Y)
        );

        return new PageUtils(page);
    }

    @Override
    public boolean DUP(String name, String phone) {
        return this.getOne(new QueryWrapper<DelivererEntity>().eq("name", name)
                .eq("status", Constant.STATE_Y).eq("phone", phone)) != null;
    }

}